<html>
<head><meta charset="utf-8"><title>Help import struct from same module · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Help.20import.20struct.20from.20same.20module.html">Help import struct from same module</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="209370715"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Help%20import%20struct%20from%20same%20module/near/209370715" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nelson nunes <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Help.20import.20struct.20from.20same.20module.html#209370715">(Sep 08 2020 at 10:54)</a>:</h4>
<p>Hi,<br>
i have this structure:</p>
<div class="codehilite"><pre><span></span><code>- main.rs
- users.rs
        - mod.rs     
        - routes.rs     
        - user.rs
</code></pre></div>


<p><strong>mod.rs</strong></p>
<div class="codehilite"><pre><span></span><code><span class="k">pub</span><span class="w"> </span><span class="k">mod</span> <span class="nn">user</span><span class="p">;</span><span class="w"></span>
<span class="k">pub</span><span class="w"> </span><span class="k">mod</span> <span class="nn">routes</span><span class="p">;</span><span class="w"></span>
</code></pre></div>


<p><strong>user.rs</strong></p>
<div class="codehilite"><pre><span></span><code><span class="k">pub</span><span class="w"> </span><span class="k">struct</span> <span class="nc">User</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">pub</span><span class="w"> </span><span class="n">id</span>: <span class="nb">Option</span><span class="o">&lt;</span><span class="kt">i32</span><span class="o">&gt;</span><span class="p">,</span><span class="w"></span>
<span class="w">    </span><span class="k">pub</span><span class="w"> </span><span class="n">firstname</span>: <span class="nb">String</span><span class="p">,</span><span class="w"></span>
<span class="w">    </span><span class="k">pub</span><span class="w"> </span><span class="n">lastname</span>: <span class="nb">String</span><span class="p">,</span><span class="w"></span>
<span class="w">    </span><span class="k">pub</span><span class="w"> </span><span class="n">email</span>: <span class="nb">String</span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>


<p>then in <strong>routes.rs</strong>, i want to use <strong>User struct</strong> but i dont know how :( i try several things without success..</p>



<a name="209370890"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Help%20import%20struct%20from%20same%20module/near/209370890" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Help.20import.20struct.20from.20same.20module.html#209370890">(Sep 08 2020 at 10:56)</a>:</h4>
<p><span class="user-mention" data-user-id="337417">@nelson nunes</span> Where do you want to use it? In which file?</p>



<a name="209370916"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Help%20import%20struct%20from%20same%20module/near/209370916" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nelson nunes <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Help.20import.20struct.20from.20same.20module.html#209370916">(Sep 08 2020 at 10:56)</a>:</h4>
<p>hi,<br>
in <a href="http://routes.rs">routes.rs</a></p>



<a name="209370956"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Help%20import%20struct%20from%20same%20module/near/209370956" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Help.20import.20struct.20from.20same.20module.html#209370956">(Sep 08 2020 at 10:57)</a>:</h4>
<p>You can add <code>use crate::users::user::User;</code> to <code>routes.rs</code>.</p>



<a name="209371018"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Help%20import%20struct%20from%20same%20module/near/209371018" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Help.20import.20struct.20from.20same.20module.html#209371018">(Sep 08 2020 at 10:58)</a>:</h4>
<p>does one of</p>
<div class="codehilite"><pre><span></span><code><span class="k">use</span><span class="w"> </span><span class="n">users</span>::<span class="n">user</span>::<span class="n">User</span><span class="p">;</span><span class="w"></span>
</code></pre></div>


<p>or</p>
<div class="codehilite"><pre><span></span><code><span class="k">use</span><span class="w"> </span><span class="k">super</span>::<span class="n">user</span>::<span class="n">User</span><span class="p">;</span><span class="w"></span>
</code></pre></div>


<p>work for you heere?</p>



<a name="209371206"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Help%20import%20struct%20from%20same%20module/near/209371206" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nelson nunes <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Help.20import.20struct.20from.20same.20module.html#209371206">(Sep 08 2020 at 11:01)</a>:</h4>
<p>awesome, this one work : use super::user::User;</p>
<p>Thanks :)</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>